package de.vogella.algorithms.dijkstra.model;
import java.text.DecimalFormat; 
import java.util.Random;
public class SpeedCalculation {
		public static double speed() {
			double a[],min,temp,speed=0,s,sum=0,sum1=0,e,Smin;
			double Smax;
			int b[],max=0;
			b=new int[50];
			a=new double[1000];
			int i,k,pace=10,j,n;
			for(i=0;i<100;i++)
			{
				Random r=new Random();
			    a[i]=r.nextDouble()*30+20;
			}
			for (i=0;i<999;i++)
			{   min=a[i];
				for (j=i+1;j<1000;j++)
				{
					if (min>a[j])
					{
						temp=min;
						a[i]=a[j];
						a[j]=temp;
					}
				}
			}
			
			
		    for(i=0;i<50;i++)
		    {
		    	    n=0;
		    		for(k=0;k<999;k++)
		    		{
		    			if((a[k]>i+20) && (a[k]<i+20+pace))
		    			n=n+1;
		    		}
		    		b[i]=n;	
		    	
		    }
		    
		    for (i=0;i<50;i++)
		    {   
		    	if (max<b[i])
				{
					max=b[i];
					speed=(a[i]+a[i+pace])/2;
				}
		    }
		
		    i=0;
		    while(i<1000)
		    {
		    	sum=a[i]+sum;
		    	i=i+1;
		    }
		    s=sum/1000;
		    while(i<1000)
		    {
		    	sum1=(a[i]-s)*(a[i]-s)+sum;
		    	i=i+1;
		    }
		    e=java.lang.StrictMath.pow(sum1/999,1.0/2); 
		    Smax=s+e;
		    return Smax;
		}
		
	}